package com.fhminyi.util;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.logging.Logger;

public class FileUploadUtil {
    private static final Logger logger = Logger.getLogger(FileUploadUtil.class.getName());

    // 上传文件到指定路径
    public static void uploadFile(String uploadDir, String fileName, byte[] fileData) throws IOException {
        Path uploadPath = Paths.get(uploadDir);

        try {
            if (!Files.exists(uploadPath)) {
                Files.createDirectories(uploadPath);
            }

            Path filePath = uploadPath.resolve(fileName);
            Files.write(filePath, fileData);
        } catch (IOException e) {
            logger.severe("Failed to upload file: " + e.getMessage());
            throw e;
        }
    }
}